package com.icss.ah.login.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.icss.ah.base.bean.EasyuiDataGridJson;

/**
 * 公告提醒
 * @author csadchen
 * @date 2017-07-21
 */
@Service
public class TipsService {
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");

	/**
	 * 获取公告提醒列表
	 * @param map
	 * @return
	 */
	public EasyuiDataGridJson queryTipsListPage(HashMap map){
		EasyuiDataGridJson dataGridJson = new EasyuiDataGridJson();
		try {
			List list = sqlSessionTemplate.selectList("TipsBean.queryTipsListPage", map);
			//记录日志
			infolog.info("TipsService|queryTipsListPage|list:"+list.size());
			dataGridJson.setRows(list);
			Long total = sqlSessionTemplate.selectOne("TipsBean.queryTipsListPageCount", map);
			//记录日志
			infolog.info("TipsService|queryTipsListPage|total:"+total);
			dataGridJson.setTotal(total);
		} catch (Exception e) {
			errlog.error("TipsService|queryTipsListPage|异常：",e);
		}
		return dataGridJson;
	}
	/**
	 * 获取公告提醒列表
	 * @param map
	 * @return
	 */
	public List queryTipsList(HashMap map){
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList("TipsBean.queryTipsList", map);
			list = list == null ? new ArrayList() : list;
		} catch (Exception e) {
			errlog.error("TipsService|queryTipsList|异常：",e);
		}
		return list;
	}
	/**
	 * 保存公告提醒阅读信息
	 * @param map
	 * @return
	 */
	public boolean readTips(HashMap map){
		boolean result = false;
		try {
			//将公告提醒信息转入已读表
			sqlSessionTemplate.insert("TipsBean.insertTipsReadByIds", map);
			//更改已在已读表中未读状态的公告提醒信息
			sqlSessionTemplate.update("TipsBean.updateTipsReadByIds", map);
			result = true;
		} catch (Exception e) {
			errlog.error("TipsService|readTips|异常：",e);
		}
		return result;
	}
}
